<?php

/**
* @Author:  	Daniel Dinh
* @Email:   	webdevelopmentvn@gmail.com
* @Link: 		http://joomsoft.net
* @Version: 	1.0
* @copyright:	Joomsoft.net
* @license:		GNU Lesser GPL
*/

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.controllerform');

class FarmacityControllerWeektime extends JControllerForm
{
	/**
	 * @var    string  The prefix to use with controller messages.
	 * @since  1.6
	 */
	protected $text_prefix = 'COM_FARMACITY_WEEKTIME';

	/**
	 * Method override to check if you can add a new record.
	 *
	 * @param   array  $data  An array of input data.
	 *
	 * @return  boolean
	 *
	 * @since   1.6
	 */
	
	 
	protected function allowAdd($data = array())
	{
		// Initialise variables.
		$user		= JFactory::getUser();
		if ($allow === null)
		{
			// In the absence of better information, revert to the component permissions.
			return parent::allowAdd($data);
		}
		else
		{
			return $allow;
		}
	}

	
	function process()
	{
		$types = JRequest::getVar('types');
		$db = & JFactory::getDBO();
		$user = & JFActory::getUser();
		if($types ==0) //single
		{
			//save
			$db->setQuery("INSERT INTO #__far_tipo_orario values('',".JRequest::getVar('types').",".JRequest::getVar('id_period').",".$user->id.")");
			$db->query();

			$mess = JText::_("COM_FARMACITY_ACTION_SAVE_SUCCESS");
			$url = "index.php?option=com_farmacity&view=periods";
		}else{
			$_SESSION['id_period'] = JRequest::getVar('id_period');
			$_SESSION['types'] = JRequest::getVar('types');
			$_SESSION['pid'] = JRequest::getVar('pid');
			$url = "index.php?option=com_farmacity&view=timeslot&layout=edit";
		}
		$this->setRedirect(JRoute::_($url,0,2),$mess);
	}

	function edit()
	{
		$_SESSION['pid'] = JRequest::getVar('pid');
		parent::edit();
	}
}
